//import axios from "@/libs/axios";
import axios from '@/libs/api.request';
import { getToken } from '@/libs/util';
/*
分页查询机构
 */
export const queryPage = (param) => {
  return axios.request({
    url: '/admin/organization/query/view/page/',
    method: 'post',
    dataType: 'json',
    headers: {
      'Content-Type': 'application/json; charset=UTF-8',
      'token': getToken()
    },
    data: param
  })
}


/*
新增机构
 */
export const addOrg = (param) => {
  return axios.request({
    url: '/admin/organization/add/',
    method: 'post',
    dataType: 'json',
    headers: {
      'Content-Type': 'application/json; charset=UTF-8',
      'token': getToken()
    },
    data: param
  })
}
/**
 * 修改机构单位
 * @param param
 * @returns {*}
 */
export const updateOrg = (param) => {
  return axios.request({
    url: '/admin/organization/update/',
    method: 'post',
    dataType: 'json',
    headers: {
      'Content-Type': 'application/json; charset=UTF-8',
      'token': getToken()
    },
    data: param
  })
}
/**
 * 删除
 * @param param
 * @returns {*}
 */
export const removeOrg = (param) => {

  let result =  axios.request({
    url: '/admin/organization/delete/',
    method: 'post',
    dataType: 'json',
    headers: {
      'Content-Type': 'application/json; charset=UTF-8',
      'token': getToken()
    },
    data: param
  })

  return result;
}





/**
 * 第一层分页查询
 * @param param
 * @returns {AxiosPromise}
 */
export const queryToplayerPage = (param) => {
  return axios.request({
    //url: '/admin/organization/query/toplayer/page',
    url: '/admin/organization/query/extent/page',
    method: 'post',
    dataType: 'json',
    headers: {
      'Content-Type': 'application/json; charset=UTF-8',
      'token': getToken()
    },
    data: param
  })
}


/**
 * 根据parentId查子机构
 * @param param
 * @returns {*}
 */
export const queryChildrens = (param) => {
  console.log(param);
  return axios.request({
    url: '/admin/organization/query/list/where',
    //url: '/admin/organization/query/childrens?parentId='+param,
    method: 'post',
    dataType: 'json',
    headers: {
      'Content-Type': 'application/json; charset=UTF-8',
      'token': getToken()
    },
    data: param
  });
}


/**
 * 深度查询所有机构
 * @param param
 * @returns {*}
 */

export const queryDepthChildrens = () => {
  return axios.request({
    url: '/admin/organization/query/depthChildrens',
    method: 'get',
    dataType: 'json',
    headers: {
      'Content-Type': 'application/json; charset=UTF-8',
      'token': getToken()
    }
  })
}
